import { RegisterComponent } from '@feng3d/ecs';
import { PerspectiveCamera3D, Scene3D, WebGLRenderer3D } from 'feng3d-three';
import { CinematicCamera } from '../thirdparty/three/imports';

declare module '@feng3d/ecs'
{
    interface ComponentMap { CinematicCamera3D: CinematicCamera3D; }
}

/**
 * 包装`three`中`CinematicCamera`。
 */
@RegisterComponent({ name: 'CinematicCamera3D' })
export class CinematicCamera3D extends PerspectiveCamera3D
{
    /**
     * @private
     */
    get _camera()
    {
        if (!this.__camera)
        {
            this.__camera = new CinematicCamera(this.fov, this.aspect, this.near, this.far);
        }

        return this.__camera;
    }
    set _camera(v)
    {
        this.__camera = v;
    }
    declare protected __camera: CinematicCamera;

    get postprocessing()
    {
        return this._camera.postprocessing;
    }
    set postprocessing(v)
    {
        this._camera.postprocessing = v;
    }

    get coc()
    {
        return this._camera.coc;
    }
    set coc(v)
    {
        this._camera.coc = v;
    }

    get frameHeight(): number
    {
        return this._camera['frameHeight'];
    }
    set frameHeight(v)
    {
        this._camera['frameHeight'] = v;
    }

    setLens(focalLength: number, frameHeight?: number, fNumber?: number, coc?: number)
    {
        this._camera.setLens(focalLength, frameHeight, fNumber, coc);
    }

    focusAt(focusDistance: number)
    {
        this._camera.focusAt(focusDistance);
    }

    renderCinematic(scene: Scene3D, renderer: WebGLRenderer3D)
    {
        this._camera.renderCinematic(scene._scene, renderer._webGLRenderer);
    }
}
